package com.google.code.irouter.portal.client.dashboard.main.north.menu.account;

import com.google.code.irouter.portal.client.dashboard.main.north.menu.account.commands.Logout;
import com.google.code.irouter.portal.client.rpc.account.AccountResult;
import com.google.code.irouter.portal.client.rpc.account.AccountService;
import com.google.code.irouter.portal.client.rpc.account.AccountServiceAsync;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.gwtext.client.widgets.menu.Menu;

public final class Commands extends Menu {
	
	private final AccountServiceAsync accountService = GWT.create(AccountService.class);
	
	public Commands() {
		super();
		this.setId(Commands.class.getName());
		
		this.addItem(new Logout());
		this.addListener(new CommandsListener());
	}
	
	public void logout() {
		accountService.logout(
				new AsyncCallback<AccountResult>() {
					public void onFailure(Throwable caught) {
					// TODO
					}

					public void onSuccess(AccountResult accountResult) {
						Window.open(accountResult.getUrl(), "_self", "");
					}
				}
		);
	}

}
